package com.tangoj.common.utils;

import cn.hutool.json.JSONUtil;
import com.tangoj.common.common.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

import static com.tangoj.common.constant.RedisConstant.LOGIN_TOKEN;

@Service
public class LoginHelper {

    public static UserVO getUser(StringRedisTemplate stringRedisTemplate,HttpServletRequest request){
        String token = request.getHeader("zhb");
        if (token == null) return null;

        if (stringRedisTemplate == null){
            System.out.println("你是空");
        }
        String userStr = stringRedisTemplate.opsForValue().get(LOGIN_TOKEN + token);
        if (userStr == null) return null;

        return JSONUtil.toBean(userStr,UserVO.class);
    }
}
